/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.jxc.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.jxc.entity.JxcPurchasekind;
import com.thinkgem.jeesite.modules.jxc.service.JxcPurchasekindService;

/**
 * 客户类别Controller
 * @author 马万进
 * @version 2016-07-19
 */
@Controller
@RequestMapping(value = "${adminPath}/jxc/jxcPurchasekind")
public class JxcPurchasekindController extends BaseController {

	@Autowired
	private JxcPurchasekindService jxcPurchasekindService;
	
	@ModelAttribute
	public JxcPurchasekind get(@RequestParam(required=false) String id) {
		JxcPurchasekind entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = jxcPurchasekindService.get(id);
		}
		if (entity == null){
			entity = new JxcPurchasekind();
		}
		return entity;
	}
	
	@RequiresPermissions("jxc:jxcPurchasekind:view")
	@RequestMapping(value = {"list", ""})
	public String list(JxcPurchasekind jxcPurchasekind, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<JxcPurchasekind> page = jxcPurchasekindService.findPage(new Page<JxcPurchasekind>(request, response), jxcPurchasekind); 
		model.addAttribute("page", page);
		return "modules/jxc/jxcPurchasekindList";
	}

	@RequiresPermissions("jxc:jxcPurchasekind:view")
	@RequestMapping(value = "form")
	public String form(JxcPurchasekind jxcPurchasekind, Model model) {
		model.addAttribute("jxcPurchasekind", jxcPurchasekind);
		return "modules/jxc/jxcPurchasekindForm";
	}

	@RequiresPermissions("jxc:jxcPurchasekind:edit")
	@RequestMapping(value = "save")
	public String save(JxcPurchasekind jxcPurchasekind, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, jxcPurchasekind)){
			return form(jxcPurchasekind, model);
		}
		jxcPurchasekindService.save(jxcPurchasekind);
		addMessage(redirectAttributes, "保存客户类别成功");
		return "redirect:"+Global.getAdminPath()+"/jxc/jxcPurchasekind/?repage";
	}
	
	@RequiresPermissions("jxc:jxcPurchasekind:edit")
	@RequestMapping(value = "delete")
	public String delete(JxcPurchasekind jxcPurchasekind, RedirectAttributes redirectAttributes) {
		jxcPurchasekindService.delete(jxcPurchasekind);
		addMessage(redirectAttributes, "删除客户类别成功");
		return "redirect:"+Global.getAdminPath()+"/jxc/jxcPurchasekind/?repage";
	}

}